<?php

    function htmlNewLine() {
        echo "<br>";
    }

    //表格工具类
    class SimpleTable {

        //行数据
        var $lines = array();

        //表格对象
        var $tableStr = "";
        var $tableContent = "";

        var $tableHead = "
            <table>
                <thead>
                    <tr>
                        <th>学生ID</th>
                        <th>姓名</th>
                        <th>考勤时间</th>
                    </tr>
                </thead>
            <tbody>";
        
        var $tableEnd = "
                </tbody>
            </table>";

        function __construct() {


        }

        function pushLine($line) {
            
            array_push($this->lines, $line);
        }

        //生成表格内容(行和列)
        function generateTableContent() {
            
            for($i = 0; $i < count($this->lines); $i++) {

                //单个学生信息
                //格式: 学生ID,姓名,考勤时间
                $studentInfo = explode(",", $this->lines[$i]);

                $this->tableContent = $this->tableContent . 
                "
                <tr>"
                .
                "<td>" . $studentInfo[0] . "</td>"
                .
                "<td>" . $studentInfo[1] . "</td>"
                .
                "<td>" . $studentInfo[2] . "</td>"
                .
                "</tr>";
            }
            return $this->tableContent;
        }

        //生成表格(可直接打印在html里)
        function generateTable() {

            $this->tableStr = $this->tableStr . $this->tableHead . 
            $this->generateTableContent() .
            $this->tableEnd;
            return $this->tableStr;
        } 

        function clearTable() {
            $this->lines = array();
        }

        //更新表格(当表格的内容发生变动时调用)
        function updateTable() {

            $this->generateTable();
        }

        function getRawTable() {

            return $this->tableStr;
        }
    }
?>